import { ref } from 'vue';

export function usePopup(cb?: () => void) {
  const popupRef = ref();
  const isHidden = ref(false);

  function open() {
    isHidden.value = false;
    popupRef.value?.open();
    if (typeof cb === 'function') {
      cb();
    }
  }

  function close() {
    isHidden.value = true;
    popupRef.value?.close();
  }

  return {
    popupRef,
    isHidden,
    open,
    close
  };
}
